<template>
  <div class="nav-bar">
    <div class="nav-bar-left" @click="back">
      <i class="icon icon-back"></i>
    </div>
    <p class="nav-bar-title">{{ title }}</p>
    <div class="nav-bar-right">
      <slot name="right"></slot>
    </div>
  </div>
</template>

<script>
import { useRouter } from "vue-router";

export default {
  props: {
    title: {
      type: String,
      default: "标题",
    },
  },
  setup() {
    const router = useRouter();
    const back = () => {
      if (window.history.length <= 1) {
        router.push({ path: "/" });
        return false;
      } else {
        router.go(-1);
      }
      
    };
    return {
      back,
    };
  },
};
</script>

<style lang="scss" scoped>
.nav-bar {
  @include flex-center;
  position: relative;
  line-height: 44px;

  &-left {
    position: absolute;
    left: 16px;
    top: 0;
  }

  &-title {
    font-size: 16px;
    font-weight: bold;
  }

  &-right {
    position: absolute;
    right: 16px;
    top: 0;
  }
}
</style>>